package com.ruoyi.blogs.service.impl;

import java.util.List;
import java.util.Map;

import com.ruoyi.blogs.domain.vo.BsNoteVo;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.mapper.SysUserMapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.blogs.mapper.BsNoteMapper;
import com.ruoyi.blogs.domain.BsNote;
import com.ruoyi.blogs.service.IBsNoteService;

/**
 * 笔记管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-01
 */
@Service
public class BsNoteServiceImpl implements IBsNoteService 
{
    @Autowired
    private BsNoteMapper bsNoteMapper;

    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询笔记管理
     * 
     * @param id 笔记管理主键
     * @return 笔记管理
     */
    @Override
    public BsNote selectBsNoteById(String id)
    {
        return bsNoteMapper.selectBsNoteById(id);
    }

    /**
     * 查询笔记管理列表
     * 
     * @param bsNote 笔记管理
     * @return 笔记管理
     */
    @Override
    public List<BsNote> selectBsNoteList(BsNote bsNote)
    {
        return bsNoteMapper.selectBsNoteList(bsNote);
    }

    /**
     * 新增笔记管理
     * 
     * @param bsNote 笔记管理
     * @return 结果
     */
    @Override
    public int insertBsNote(BsNote bsNote)
    {
        SysUser user = new SysUser();
        user.setUserId(SecurityUtils.getUserId());
        user.setNoteNum(0);
        userMapper.updateUserNum(user);
        bsNote.setCreateTime(DateUtils.getNowDate());
        bsNote.setUpdateTime(DateUtils.getNowDate());
        bsNote.setAuthorId(SecurityUtils.getUserId());
        bsNote.setUserName(SecurityUtils.getUsername());
        bsNote.setPageViewNum(0L);
        bsNote.setCollectNum(0L);
        bsNote.setLikeNum(0L);
        return bsNoteMapper.insertBsNote(bsNote);
    }

    /**
     * 修改笔记管理
     * 
     * @param bsNote 笔记管理
     * @return 结果
     */
    @Override
    public int updateBsNote(BsNote bsNote)
    {
        bsNote.setUpdateTime(DateUtils.getNowDate());
        return bsNoteMapper.updateBsNote(bsNote);
    }

    /**
     * 批量删除笔记管理
     * 
     * @param ids 需要删除的笔记管理主键
     * @return 结果
     */
    @Override
    public int deleteBsNoteByIds(String[] ids)
    {
        SysUser user = new SysUser();
        user.setUserId(SecurityUtils.getUserId());
        user.setNoteNum(1);
        user.setSearchValue(Integer.toString(ids.length));
        userMapper.updateUserNum(user);
        return bsNoteMapper.deleteBsNoteByIds(ids);
    }

    /**
     * 删除笔记管理信息
     * 
     * @param id 笔记管理主键
     * @return 结果
     */
    @Override
    public int deleteBsNoteById(String id)
    {
        return bsNoteMapper.deleteBsNoteById(id);
    }

    @Override
    public int batchUpdateBsNote(Map<String, Object> map) {
        return bsNoteMapper.batchUpdateBsNote(map);
    }

    @Override
    public int updateBsNoteLike(Map<String, Object> map) {
        return bsNoteMapper.updateBsNoteLike(map);
    }

    @Override
    public List<BsNoteVo> selectBsNoteVoList(BsNote bsNote) {
        return bsNoteMapper.selectBsNoteVoList(bsNote);
    }

    @Override
    public BsNoteVo selectBsNoteVoByQuery(Map<String, Object> map) {
        return bsNoteMapper.selectBsNoteVoByQuery(map);
    }

    @Override
    public int updateBsNoteViewById(BsNote bsNote) {
        return bsNoteMapper.updateBsNoteViewById(bsNote);
    }
}
